import { createRouter, createWebHistory } from 'vue-router'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {path:'/',redirect:'/home'},
    {path:'/home',name:'home',components:{
      default: ()=>import('@/views/home/MyHome.vue'),
      footer:()=>import('@/components/Footer.vue')
    }},
    {path:'/kind',name:'kind',components:{
      default:()=>import('@/views/kind/MyKind.vue'),
      footer:()=>import('@/components/Footer.vue')
    }},
    {path:'/cart',meta:{requiresAuth:true},name:'cart',components:{
      default:()=>import('@/views/cart/Mycart.vue'),
      footer:()=>import('@/components/Footer.vue')
    }},
    {path:'/my',meta:{requiresAuth:true},name:'my',components:{
      default:()=>import('@/views/my/MyView.vue'),
      footer:()=>import('@/components/Footer.vue')
    }},
    {path:'/user',name:'user',component:()=>import('@/views/user/Zhuce.vue'),children:[
        {path:'/user/',redirect:'/user/checktel'},
        {path:'checktel',component:()=>import("@/views/user/components/Checktel.vue")},
        {path:'sendmsg',component:()=>import('@/views/user/components/Sendmsg.vue')},
        {path:'setpass',component:()=>import('@/views/user/components/Setpass.vue')},
      ]
    },
    {path:'/denglu',name:'denglu',component:()=>import('@/views/user/Denglu.vue')},
    {path:'/xq/:proid',meta:{requiresAuth:true},name:'xq',component:()=>import('@/views/xiangqingye/xq.vue')}
  ],
})
import auth from '@/atils/auth'
router.beforeEach((to,from)=>{
    if(to.meta.requiresAuth && !auth.isLoggedIn()){
      return {
        path:'/denglu',
        query:{redirect:to.fullPath},
      }
    }
})
export default router
